<template>
	<view class="p-3">
		<public-module></public-module>
		<view class="flex j-start a-center p-3 bg-white rounded-10 mb-2" v-for="(item,index) in listData" :key="item.id"
			@click="navigateTo('/pages/activity/turntable?id='+item.id)">
			<u--image v-if="index==0" :showLoading="true"
				src="https://imgurl.haiminglan.cn/8d9aee1b4843f05d5006b79a37c1aad831e6133669167dcd380bb974011b2455.jpeg"
				width="160rpx" height="160rpx" :radius="10">
				<view slot="error" style="font-size: 22rpx;">图片加载失败</view>
			</u--image>
			<u--image v-else :showLoading="true"
				src="https://imgurl.haiminglan.cn/5026e87ab2d16d0ef13b0757b8063e11f927f6726a92b063c932c7ed3b009a01.jpg"
				width="160rpx" height="160rpx" :radius="10">
				<view slot="error" style="font-size: 22rpx;">图片加载失败</view>
			</u--image>
			<view class="ml-2" style="width: 460rpx;">
				<view class="mb-1 font-bold font-32 ellipsis">{{item.name}}</view>
				<view class="mb-1 font-24 ellipsis2">{{item.name}}</view>
				<view class="text-secondary">{{$dateFormat(item.beginTime)}}~{{$dateFormat(item.endTime)}}</view>
			</view>
		</view>

		<empty v-if="listData.length==0" />
	</view>
</template>

<script>
	import {
		activityList
	} from '@/api/active.js'

	export default {
		data() {
			return {
				queryParams: {
					pageNo: 1,
					pageSize: 15,
				},
				listData: []
			}
		},
		onLoad() {
			this.getDataLists()
		},
		onPullDownRefresh() {
			this.isLoadMore = false;
			this.queryParams.pageNo = 1;
			this.listData = [];
			this.getDataLists();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 500);
		},
		onReachBottom() {
			if (!this.isLoadMore) {
				this.isLoadMore = true;
				this.queryParams.pageNo += 1;
				this.getDataLists();
			}
		},
		methods: {
			getDataLists() {
				activityList(this.queryParams).then(res => {
					if (res.data.list.length == 0) {
						let oldLoad = {}
						this.isLoadMore = true;
						oldLoad = Object.assign({}, this.queryParams);
						oldLoad.pageNo = this.queryParams.pageNo;
						this.queryParams = oldLoad
						this.$forceUpdate()
						return
					}

					this.isLoadMore = false;
					let oldList = this.listData || []
					oldList.push(...res.data.list)
					this.listData = oldList
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>